﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		Plugin.Validation.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 // 
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 

using System;
using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class Plugin {
		/// <summary>
		/// Validate the current instance before to created.
		/// </summary>
		/// <returns>A new instance of <see cref="BlogRoll"/></returns>
		/// <exception cref="ArgumentNullException"> If <see cref="Plugin.Name"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentOutOfRangeException">If <see cref="Plugin.Name"/> is <c>empty</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <see cref="Plugin.Version"/> is <c>null</c>.</exception>
		public virtual void ValidateForSave ( ) {
			BaseValidation ( );
		}

		/// <summary>
		/// Validate the current instance before to updated.
		/// </summary>
		/// <returns>A new instance of <see cref="BlogRoll"/></returns>
		/// <exception cref="ArgumentNullException"> If <see cref="Plugin.Name"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentOutOfRangeException">If <see cref="Plugin.Name"/> is <c>empty</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <see cref="Plugin.Version"/> is <c>null</c>.</exception>
		public virtual void ValidateForUpdate ( ) {
			ValidateKey ( );

			BaseValidation ( );
		}

		/// <summary>
		/// Validate the current instance before to be deleted.
		/// </summary>
		/// <returns>A new instance of <see cref="BlogRoll"/></returns>
		/// <exception cref="ArgumentNullException"> If <see cref="Plugin.Name"/> is <c>null</c>.</exception>
		/// <exception cref="ArgumentOutOfRangeException">If <see cref="Plugin.Name"/> is <c>empty</c>.</exception>
		/// <exception cref="ArgumentNullException"> If <see cref="Plugin.Version"/> is <c>null</c>.</exception>
		public virtual void ValidateForDelete ( ) {
			ValidateKey ( );
		}

		void ValidateKey ( ) {
			Ensure.That ( Id )
				.Named ( "obj.Id" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsGreaterThen ( 0 )
				.WithMessage ( "Invalid Plugin Key" );
		}

		void BaseValidation ( ) {
			Ensure.That ( this.Version )
				.Named ( "Version" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsNotNull ( )
				.WithMessage ( "Invalid plugin version." );

			Ensure.That ( this.Name )
				.Named ( "Name" )
				.WithPreview ( ( v, e ) => Logger.Warn ( v.GetFullErrorMessage ( ), e ) )
				.IsNotNullNorEmpty ( )
				.WithMessage ( "Invalid plugin name." );
		}
	}
}
